<?php
/**
 * 用户登录逻辑开发
 */

namespace app\api\controller;


use app\api\validate\User;
use app\BaseController;
use app\common\lib\Show;

class Login extends BaseController
{
    /**
     * 短信验证码登录
     */
    public function loginByPhoneSms() {
        if (!$this->request->isPost()) {
            return show(config('status.error', '非法请求'));
        }
        $phoneNumber = $this->request->param('phone_number', "", "trim");
        $code = $this->request->param('code', '', "intval");
        $type = $this->request->param('type', '', "intval");
        //校验参数
        $data = [
            "phone_number" => $phoneNumber,
            "code" => $code,
            "type" => $type
        ];
        $validate = new User();
        if (!$validate->scene('login')->check($data)) {
            return Show::error($validate);
        }
        //验证信息
        $result = (new \app\common\business\User())->loginByPhone($data);
        if ($result) {
            return Show::success($result);
        }
        return Show::error();

    }
}